<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules//vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
         <ul>
            <li>西游记；价格:{{xyjPrice}},数量：<input type="number" v-model="xyjNum"></li>
            <li>水浒传；价格:{{shzPrice}},数量：<input type="number" v-model="shzNum"></li>
            <li>总价：{{taotalPrice}}</li>
            {{msg}}
         </ul>
    </div>
    
</body>
<script>
    new Vue({
        el: "#app",
        data:{
            xyjPrice: 50.00,
            shzPrice: 100.00,
            xyjNum:1,
            shzNum:1,
            //taotalPrice:0,
            msg: ""
        },
        computed: {//计算属性
            taotalPrice(){
                return this.xyjPrice*this.xyjNum + this.shzNum*this.shzPrice;
            }
        },
        methods: {
            
        },
        watch:{//可以让我们监控一个值的变化，从而做到相应的梵音
            xyjNum(newVal,oldVal){
                console.log("newVal",newVal);
                console.log("oldVal",oldVal);
                if(newVal >= 3){
                    this.msg = "超出库存限制";
                    this.xyjNum = 3;
                }else{
                    this.msg = "";
                }
            }  
        }
    })

</script>

</html>